﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;
using DataAccess;
using Model.CustomDataType;

namespace BusinessLogic
{
    public class PrescriptionBL: MarshalByRefObject
    {
        private PrescriptionDA preDA;
        /// <summary>
        /// Constructor for Patient Busines Logic tier.
        /// Note: Close this if you don't retrieve data any more use close() method to close an existing connection
        /// Always check connection before doing anything relates to SQL Connection task.
        /// </summary>
        public PrescriptionBL()
        {
            preDA = new PrescriptionDA();
            
        }
        public Prescription createPrescrition()
        {
            return new Prescription();
        }
        public PrescriptionDetail createPrescritionDetail()
        {
            return new PrescriptionDetail();
        }
        public override object InitializeLifetimeService()
        {
            return null;// live forever;
        }
        
        public Prescription getPrescriptionById(int id)
        {
            if (id < 1)
            {
                return null;
            }
            else
            {
                return preDA.getPrescriptionById(id);
            }
        }
        
        public int addPrescription(Prescription pre)
        {
            if(pre==null)
            {
                return -1;
            }
            else
            {
                return preDA.addPrescription(pre);
            }
        }
        
        public bool updatePrescription(Prescription pre)
        {
            if(pre == null)
            {
                return false;
            }
            else
            {
                return preDA.updatePrescription(pre);
            }
        }

        public Prescription[] getPrescriptionsByName(string name)
        {
            return preDA.getPrescriptionsByName(name);
        }

        public Prescription[] getAllPrescription()
        {
            return preDA.getAllPrescription();
        }

        public Prescription[] getPrescriptionsByRawQuery(string query)
        {
            if (query == "")
            {
                return null;
            }
            else
            {
                return preDA.getPrescriptionsByRawQuery(query);
            }
        }
        ////////////////////////////////////////////////
        //
        // Prescription Detail
        //
        ////////////////////////////////////////////////

        public bool addPrescriptionDetail(PrescriptionDetail preDe)
        {
            if(preDA==null)
            {
                return false;
            }
            else
            {
                return preDA.addPrescriptionDetail(preDe);
            }

        }

        public bool updatePrescriptionDetail(PrescriptionDetail preDe)
        {
            if(preDe==null)
            {
                return false;
            }
            else
            {
                return preDA.updatePrescriptionDetail(preDe);
            }
        }

        public PrescriptionDetail getPrescriptionDetailById(int preDeId)
        {
            return preDA.getPrescriptionDetailById(preDeId);

        }

        public PrescriptionDetail[] getAllPrescriptionDetail()
        {
            return preDA.getAllPrescriptionDetail();


        }

        public PrescriptionDetail[] getPrescriptionDetailsByRawQuery(string query)
        {
            return preDA.getPrescriptionDetailsByRawQuery(query);
        }
        
    }
}
